/*

Author   : chaos

FileName : comp_ref.cpp

Date     : 15/08/17 03:04:34

*/
#include <iostream>
using namespace std;

class Base
{
    public:
        Base()
        {cout << "Base's constructor is called!" << endl;}
};

class Composition_1
{
    public:
        Composition_1()
        {cout << "Composition_1's constructor is called !" << endl;}
        void show()
        { cout << "Composition_1::show is called !" << endl; }
};

class Composition_2
{
    public:
        Composition_2()
        { cout << "Composition_2's constructor is called!" << endl; }
        void show()
        { cout << "Composition_2::show is called !" << endl; }
};

class Derived:public Base
{
    public:
        Composition_2 * com_2;
        Composition_1 & com_1;

        Derived(Composition_1 & com_1_ref, Composition_2 * com_2_ptr)
            :com_1(com_1_ref),com_2(com_2_ptr)
        {cout << "Derived's comstructor is called !" << endl;}

        Derived(Composition_1 & com_1_ref):com_1(com_1_ref)
        { cout << "Derived's constructor is called!" << endl; }
};


int main(int argc ,char *argv[])
{
    Composition_1 com_1;
    Composition_2 com_2;

    Derived derived_object1(com_1,&com_2);

    Derived derived_object2(com_1);

    cout << endl;

    derived_object1.com_1.show();

    cout << endl;

    derived_object1.com_2->show();

    return 0;
}
